package io.zhoujie.modules.app.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.zhoujie.common.utils.R;
import io.zhoujie.modules.admin.entity.AppUserEntity;
import io.zhoujie.modules.app.entity.AppActiveEntity;
import io.zhoujie.modules.app.service.AppActiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 管理端——活动管理
 *
 * @author zhoujie
 * @email 813685764@qq.com
 * @date 2024-02-20 12:10:43
 */
@RestController
@Api(tags = "手机端——活动管理")
@RequestMapping("/app/active")
@Transactional(rollbackFor = Exception.class )
public class AppActiveController {
    @Autowired
    private AppActiveService appActiveService;

    /**
     * 活动列表
     *
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("活动列表")
    public R list(@RequestParam(value = "status",required = true) Integer status) {
        List<AppActiveEntity> list = appActiveService.queryByStatus(status);
        return R.ok().put("result", list);
    }

    /**
     * 点击报名
     * @param userId
     * @param activeId
     * @return
     */
    @GetMapping("/signup")
    @ApiOperation("活动报名")
    public R signup(@RequestParam(value = "user_id") Integer userId,@RequestParam(value = "active_id") Integer activeId) {
        int result = appActiveService.insertActiveByUid(userId,activeId);
        return R.ok();
    }
    /**
     * 查询活动报名情况
     * @param userId
     * @param activeId
     * @return
     */
    @GetMapping("/signinfo")
    @ApiOperation("查询活动报名情况")
    public R select(@RequestParam(value = "user_id") Integer userId,@RequestParam(value = "active_id") Integer activeId) {
        Map<Object, Object> result = appActiveService.selectActiveInfo(userId,activeId);
        return R.ok().put("result",result);
    }

    /**
     * 查询个人参加活动状况
     * @param userId
     * @return
     */
    @GetMapping("/signlist")
    @ApiOperation("查询个人参加活动状况")
        public R select(@RequestParam(value = "user_id") Integer userId) {
        List<AppActiveEntity> result = appActiveService.selectUserActive(userId);
        return R.ok().put("result",result);
    }
    @GetMapping("/delete")
    @ApiOperation("取消参加活动")
    public R delete(@RequestParam(value = "user_id") Integer userId,@RequestParam(value = "active_id") Integer activeId) {
        int result = appActiveService.deletePartActive(userId,activeId);
        return R.ok().put("result",result);
    }
}
